package com.ruoyi.web.wapper;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.wapper.BaseControllerWrapper;
import com.ruoyi.extend.enums.ChannelTypeEnum;
import com.ruoyi.market.constant.SystemConstant;

import java.util.List;
import java.util.Map;

public class ChannelInfoWapper extends BaseControllerWrapper {

    public ChannelInfoWapper(Map<String, Object> single) {
        super(single);
    }

    public ChannelInfoWapper(List<Map<String, Object>> multi) {
        super(multi);
    }

    private List<Map<String, Object>> productList;
    public ChannelInfoWapper setProductList(List<Map<String, Object>> productList) {
        this.productList = productList;
        return this;
    }

    @Override
    public void wrapTheMap(Map<String, Object> map) {

        try {

//            String notIncludeProduct = (String)map.get("notIncludeProduct");
//            JSONArray resultArray = new JSONArray();
//            JSONArray jsonArray = JSON.parseArray(notIncludeProduct);
//            if (ObjectUtil.isNotEmpty(jsonArray) && jsonArray.size() > 0){
//                for (int index = 0; index < jsonArray.size(); index++){
//                    String productId = jsonArray.getString(index);
//                    for (Map<String, Object> itemMap: productList){
//                        Long value = (Long) itemMap.get("value");
//                        String name = (String) itemMap.get("name");
//                        if (StringUtils.equals(String.valueOf(value), productId)){
//                            resultArray.add(name);
//                        }
//                    }
//                }
//            }
//            map.put("notIncludeProduct", resultArray.toJSONString());


//            String notIncludeSource = (String)map.get("notIncludeSource");
//            JSONArray resultArraySource = new JSONArray();
//            JSONArray jsonArraySource = JSON.parseArray(notIncludeSource);
//            if (ObjectUtil.isNotEmpty(jsonArraySource) && jsonArraySource.size() > 0){
//                for (int index = 0; index < jsonArraySource.size(); index++){
//                    String valueitem = jsonArraySource.getString(index);
//                    for (Map<String, Object> itemMap: SystemConstant.mapList){
//                        String value = (String) itemMap.get("value");
//                        String name = (String) itemMap.get("name");
//                        if (StringUtils.equals(value, valueitem)){
//                            resultArraySource.add(name);
//                        }
//                    }
//                }
//            }
//            map.put("notIncludeSource", resultArraySource.toJSONString());

            String channelType = (String) map.get("channelType");
            map.put("channelTypeStr", ChannelTypeEnum.getNameByValue(channelType));

        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}
